#!/usr/bin/python
# -*- coding: UTF-8 -*-


import time
import struct
import binascii
import oppleserialmsg


def port_tesing(serialclass, times, timeout):
    lost = 0
    for t in range(0, times):
        ret = serialclass.port_testing(timeout)
        if ret != "success":
            print ret
            lost += 1

    print "********"
    print "send %d lost %d rate %f%%" % (times, lost, (times - lost)/times * 100)
    print "********"

    if lost != 0:
        return "lost %d" % lost

    return "success"

